<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates SNMP instance representing session to remote SNMP agent</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="snmp.close.html">« SNMP::close</a></li>
      <li style="float: right;"><a href="snmp.get.html">SNMP::get »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.snmp.html">SNMP</a></li>
    <li>Creates SNMP instance representing session to remote SNMP agent</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="snmp.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SNMP::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SNMP::__construct</span> &mdash; <span class="dc-title">Creates SNMP instance representing session to remote <abbr title="Simple Network Management Protocol">SNMP</abbr> agent</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-snmp.construct-description">
  <h3 class="title">说明</h3>

  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SNMP::__construct</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$version</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$hostname</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$community</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$timeout</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$retries</code><span class="initializer"> = -1</span></span><br>)</div>

  <p class="para rdfs-comment">
   The function description goes here.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-snmp.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">version</code></dt>

    <dd>

     <p class="para">
      <abbr title="Simple Network Management Protocol">SNMP</abbr> protocol version:
      <strong><code>SNMP::VERSION_1</code></strong>, 
      <strong><code>SNMP::VERSION_2C</code></strong>, 
      <strong><code>SNMP::VERSION_3</code></strong>.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">hostname</code></dt>

    <dd>

     <p class="para">
      The <abbr title="Simple Network Management Protocol">SNMP</abbr> agent. <code class="parameter">hostname</code> may be suffixed with
      optional <abbr title="Simple Network Management Protocol">SNMP</abbr> agent port after colon. IPv6 addresses must be enclosed in square
      brackets if used with port. If FQDN is used for <code class="parameter">hostname</code>
      it will be resolved by php-snmp library, not by Net-SNMP engine. Usage
      of IPv6 addresses when specifying FQDN may be forced by enclosing FQDN
      into square brackets. Here it is some examples:
     <table class="doctable table">
      
      
       <tbody class="tbody">
        <tr><td>IPv4 with default port</td><td>127.0.0.1</td></tr>

        <tr><td>IPv6 with default port</td><td>::1 or [::1]</td></tr>

        <tr><td>IPv4 with specific port</td><td>127.0.0.1:1161</td></tr>

        <tr><td>IPv6 with specific port</td><td>[::1]:1161</td></tr>

        <tr><td>FQDN with default port</td><td>host.domain</td></tr>

        <tr><td>FQDN with specific port</td><td>host.domain:1161</td></tr>

        <tr><td>FQDN with default port, force usage of IPv6 address</td><td>[host.domain]</td></tr>

        <tr><td>FQDN with specific port, force usage of IPv6 address</td><td>[host.domain]:1161</td></tr>

       </tbody>
      
     </table>

     </p>
    </dd>

   
   
    <dt>
<code class="parameter">community</code></dt>

    <dd>

     <p class="para">The purpuse of <code class="parameter">community</code> is
     <abbr title="Simple Network Management Protocol">SNMP</abbr> version specific:</p>
     <table class="doctable table">
      
      
       <tbody class="tbody">
        <tr><td>SNMP::VERSION_1</td><td><abbr title="Simple Network Management Protocol">SNMP</abbr> community</td></tr>

        <tr><td>SNMP::VERSION_2C</td><td><abbr title="Simple Network Management Protocol">SNMP</abbr> community</td></tr>

        <tr><td>SNMP::VERSION_3</td><td><abbr title="Simple Network Management Protocol">SNMP</abbr>v3 securityName</td></tr>

       </tbody>
      
     </table>

    </dd>

   
    
     <dt>
<code class="parameter">timeout</code></dt>

     <dd>

      <p class="para">
       The number of microseconds until the first timeout.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">retries</code></dt>

     <dd>

      <p class="para">
       The number of retries in case timeout occurs.
      </p>
     </dd>

    
  </dl>

 </div>


 <div class="refsect1 errors" id="refsect1-snmp.construct-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   <span class="methodname"><strong>SNMP::__construct()</strong></span> throws an exception when
   parameters count or types are wrong or unknown <abbr title="Simple Network Management Protocol">SNMP</abbr>
   protocol version specified.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-snmp.construct-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="snmp.construct.example.basic">
   <p><strong>示例 #1 Fetching sysLocation</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$session&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">(</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">::</span><span style="color: #0000BB">VERSION_1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"public"</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$sysdescr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">"sysDescr.0"</span><span style="color: #007700">);<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$sysdescr</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
STRING: Test server
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-snmp.construct-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="snmp.close.html" class="methodname" rel="rdfs-seeAlso">SNMP::close()</a> - Close SNMP session</span></li>
  </ul>
 </div>


</div></div></div></body></html>